
<template>
  <el-dialog title="分配角色" :visible="showRoleDialog" @close="close">
    <!-- el-checkbox-group选中的是 当前用户所拥有的角色  需要绑定 当前用户拥有的角色-->
    <el-checkbox-group v-model="checkList">
      <el-checkbox v-for="item in rowsList" :key="item.id" :label="item.id">{{ item.name }}</el-checkbox>
    </el-checkbox-group>
    <el-row slot="footer" type="flex" justify="center">
      <el-col :span="6">
        <el-button type="primary" size="small" @click="Updaterole">确定</el-button>
        <el-button size="small" @click="close">取消</el-button>
      </el-col>
    </el-row>
  </el-dialog>
</template>

<script>
import { getroleList } from '@/api/setting'
import { getUserDetailById } from '@/api/user'
import { Updaterole } from '@/api/employee'
export default {
  props: {
    showRoleDialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      id: '',
      rowsList: [],
      checkList: []
    }
  },
  async mounted() {
    const { rows } = await getroleList()
    this.rowsList = rows
  },
  methods: {
    close() {
      this.$parent.showassigeRole = false
    },
    async rows(id) {
      this.checkList = []
      const { roleIds } = await getUserDetailById(id)
      this.checkList = roleIds
      this.id = id
    },
    async Updaterole() {
      await Updaterole({ id: this.id, roleIds: this.checkList })
      this.$message.success('更新成功')
      this.$parent.showassigeRole = false
    }
  }
}
</script>

<style>

</style>
